package com.xxx.yuedong.campaign.controller;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.json.JSONUtil;
import com.xxx.yuedong.campaign.controller.form.InsertCollectForm;
import com.xxx.yuedong.campaign.controller.form.InsertPlanForm;
import com.xxx.yuedong.campaign.controller.form.SearchCollectForm;
import com.xxx.yuedong.campaign.pojo.Collect;
import com.xxx.yuedong.campaign.pojo.Plan;
import com.xxx.yuedong.campaign.service.CollectService;
import com.xxx.yuedong.common.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author hc
 * @date 2023/08/28 22:51
 **/

@RestController
@RequestMapping("/collect")
@Api(tags = "收藏相关接口")
@Slf4j
public class CollectController {

    @Autowired
    private CollectService collectService;

    @PostMapping("/insert")
    @ApiOperation(value = "新增收藏")
    public R insert(@Valid @RequestBody InsertCollectForm form){
        log.debug("正在执行 【新增收藏】,参数为:{}" + form.toString());
        Collect collect = JSONUtil.parse(form).toBean(Collect.class);
        collect.setUserId(StpUtil.getLoginIdAsLong());
        int rows = collectService.insert(collect);
        return R.ok().put("rows",rows);
    }

    @GetMapping ("/searchCourseCollect")
    @ApiOperation(value = "查看课程收藏列表")
    public R searchCourseCollect(){
        log.debug("正在执行 【查看课程收藏列表】,参数为:{}");
        ArrayList<HashMap> list = collectService.searchCourseCollect(StpUtil.getLoginIdAsLong());
        return R.ok().put("list",list);
    }

    @GetMapping ("/searchPlanCollect")
    @ApiOperation(value = "查看计划收藏列表")
    public R searchPlanCollect(){
        log.debug("正在执行 【查看计划收藏列表】,参数为:{}");
        ArrayList<HashMap> list = collectService.searchPlanCollect(StpUtil.getLoginIdAsLong());
        return R.ok().put("list",list);
    }

}
